﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Microsoft.SharePoint.Administration;

namespace MicroLink.SharePointServices.SolutionAdministration
{
    public class SolutionDataTable : DataTable
    {
        public SolutionDataTable()
            : base()
        {
            Columns.Add("SolutionId");
            Columns.Add("SolutionName");
            Columns.Add("DeploymentState");
            Columns.Add("DeployedTo");

            SPSolutionCollection spSolutions = SPFarm.Local.Solutions;
            foreach (SPSolution spSolution in spSolutions)
            {
                string deployedTo = "Global";
                if (spSolution.ContainsWebApplicationResource)
                {
                    deployedTo = "";
                    foreach (SPWebApplication spWebApplication in spSolution.DeployedWebApplications)
                    {
                        deployedTo += spWebApplication.AlternateUrls[0].IncomingUrl + ";";
                    }
                }
                Rows.Add(spSolution.Id, spSolution.DisplayName, spSolution.DeploymentState.ToString(), deployedTo);
            }
        }
    }
}
